package com.cms.security;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.cms.framework.web.WebConstants;

public class WebSecurityUtils {
    public static LoginInfo getLoginUserInfoFromSession() {
        Subject currentUser = SecurityUtils.getSubject();
        if (!currentUser.isAuthenticated() || currentUser.getSession() == null) return null;
        return (LoginInfo) currentUser.getSession().getAttribute(WebConstants.MANAGE_INFO_ENTITY);
    }



    public static String getLoginEmail() {
    	LoginInfo loginInfo = getLoginUserInfoFromSession();
        return loginInfo != null ? loginInfo.getLoginEmail() : "";
    }
    
    public static String getUserName(){
    	LoginInfo loginInfo = getLoginUserInfoFromSession();
        return loginInfo != null ? loginInfo.getUserName() : "";
    }
}
